package com.ddtech.business.task.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddtech.business.task.query.TaskQuery;
import com.ddtech.business.task.service.TaskService;
import com.ddtech.business.task.vo.req.TaskReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 任务表 前端控制器
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-06
 */
@Api(tags = "业务-任务管理")
@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    @ApiOperation(value = "查询任务列表")
    @GetMapping(value = "/page-list")
    public ResponseEntity getPageList(TaskQuery taskQuery) {
        return new ResponseEntity(taskService.pageList(taskQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "任务详情")
    @GetMapping(value = "/info/{id}")
    public ResponseEntity info(@PathVariable String id) {
        return new ResponseEntity(taskService.info(id), HttpStatus.OK);
    }

    @ApiOperation(value = "创建任务")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody TaskReqVo taskReqVo) {
        taskService.create(taskReqVo);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "删除任务")
    @PostMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        taskService.del(id);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "查询任务进度列表")
    @GetMapping(value = "/schedule-list")
    public ResponseEntity getScheduleList(TaskQuery taskQuery) {
        return new ResponseEntity(taskService.getScheduleList(taskQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "查询考核进度列表")
    @GetMapping(value = "/schedule-check-list")
    public ResponseEntity getScheduleCheckList(@ApiParam("任务id") @RequestParam String taskId,
                                               @ApiParam("学员名称")  String userName,
                                               @RequestParam(value = "page", defaultValue = "1") int page,
                                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        IPage pageInfo = new Page(page + 1, pageSize);
        return new ResponseEntity(taskService.getScheduleCheckList(taskId, userName,pageInfo), HttpStatus.OK);
    }

    @ApiOperation(value = "我的任务)")
    @GetMapping(value = "/my-task")
    public ResponseEntity getMyTask(@ApiParam("1:完成,0未完成") @RequestParam Integer isFinish,
                                    @RequestParam(value = "page",defaultValue = "1") int page,
                                    @RequestParam(value = "pageSize",defaultValue = "10") int pageSize) {
        IPage pageInfo = new Page(page+1, pageSize);
        return new ResponseEntity(taskService.getMyTask(pageInfo,isFinish), HttpStatus.OK);
    }

}
